package leetcode_501_600;

import jdk.internal.org.objectweb.asm.tree.InsnList;
import node.TreeNode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class LeeCode_530 {
    public static void main(String[] args) {

    }
    private static int getMinimumDifference(TreeNode root) {
        List<Integer> list = new ArrayList<>();
        dfs(root, list);
        list.sort(Comparator.comparingInt(o -> o));
        int ans = Integer.MAX_VALUE;
        for (int i = 1; i < list.size(); i++) {
            ans = Math.min(list.get(i) - list.get(i - 1), ans);
        }
        return ans;
    }
    private static void dfs(TreeNode node, List<Integer> list){
        if (node == null)
            return;
        list.add(node.val);
        dfs(node.left, list);
        dfs(node.right, list);
    }
}
